package per.chenyl.framework.persistence.test.service.impl;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import per.chenyl.framework.persistence.test.entity.User;
import per.chenyl.framework.persistence.test.mapper.UserMapper;
import per.chenyl.framework.persistence.test.service.IServiceUser;
import per.chenyl.framework.persistence.test.service.IServiceUser1;
import per.chenyl.framework.persistence.wrapper.UpdateWrapper;

import java.util.List;
import java.util.Map;

/**
 * @author 陈玉林
 * @desc TODO
 * @date 2020/7/18 16:07
 */
@Service
public class UserServiceImpl1 implements IServiceUser1 {
    private final UserMapper userMapper;
    private final JdbcTemplate jdbcTemplate;

    public UserServiceImpl1(UserMapper userMapper, JdbcTemplate jdbcTemplate) {
        this.userMapper = userMapper;
        this.jdbcTemplate = jdbcTemplate;
    }


    @Override
//    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void updateOther() {
        User user = new User();
        user.setId(2);
        user.setName("name2");
//        user.setName("user2");
        userMapper.update(user, new UpdateWrapper<>());
//        List<Map<String, Object>> maps = jdbcTemplate.queryForList("SELECT TRX_ID FROM INFORMATION_SCHEMA.INNODB_TRX WHERE TRX_MYSQL_THREAD_ID = CONNECTION_ID( );");
//        System.out.println(maps + TransactionSynchronizationManager.getCurrentTransactionName());

        if (true) {
            throw new RuntimeException();
        }
    }
}
